package cn.xingyun.pickaxe_loli_new.mixin;

import cn.xingyun.pickaxe_loli_new.init.NewLoliPickaxeModItems;
import cn.xingyun.pickaxe_loli_new.item.LolipickaxeItem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(LivingEntityRenderer.class)
public class LivingEntityRendererMixin{
    @Inject(method = "getOverlayCoords",at = @At("HEAD"),cancellable = true)
    private static void getOverlayCoords(LivingEntity p_115339_, float p_115340_, CallbackInfoReturnable<Integer> cir){
        if(p_115339_ instanceof Player player && player.getInventory().contains(NewLoliPickaxeModItems.LOLIPICKAXE.get().getDefaultInstance())){
            cir.setReturnValue(OverlayTexture.pack(OverlayTexture.u(p_115340_), OverlayTexture.v(false)));
        }if (LolipickaxeItem.isBanned(p_115339_)){
            cir.setReturnValue(OverlayTexture.pack(OverlayTexture.u(p_115340_), OverlayTexture.v(true)));
        }
    }
    /*@Inject(method = "render(Lnet/minecraft/world/entity/Entity;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V",at = @At("HEAD"),cancellable = true,remap = false)
    private void render(Entity par1, float par2, float par3, PoseStack par4, MultiBufferSource par5, int par6, CallbackInfo ci){
        if (LolipickaxeItem.DarkNameList.contains(par1.getClass())){
            ci.cancel();
        }else if (par1 instanceof LivingEntity livingEntity && LolipickaxeItem.isBanned(livingEntity)){
            ci.cancel();
        }
    }*/
    @Mixin(EntityRenderer.class)
    public static class EntityRendererMixin{
        @Inject(method = "getPackedLightCoords",at = @At("HEAD"), cancellable = true)
        private <T extends Entity> void getPacked(T p_114506_, float p_114507_, CallbackInfoReturnable<Integer> cir){
            if (LolipickaxeItem.DarkNameList.contains(p_114506_.getClass().getName())){
                //cir.setReturnValue(OverlayTexture.u(p_114507_));
            }
        }
    }
}
